import request from 'umi-request';

export default {
  namespace: 'employee',

  state: [],

  reducers: {
    update(_, { payload }) {
      const { employees } = payload;
      return employees;
    },

    

    deleteEmployee(state, { payload }) {
      const { id: targetId } = payload; 
     
      return  state.filter((e) => e.key != targetId);
    },

    addEmployee(state, { payload }) {
      const { user } = payload; 
       console.log(user)
      const arr =  state.concat([user])
       console.log(arr)
      return   state.concat([user])
    },
  },

  effects: {
    *getAll(_, { call, put }) {
      const response = yield call(request.get, '/api/employees');
     
      yield put({
        type: 'update',
        payload: {
          employees: response,
        },
      });
      return  response;
    },

  },
};
